package com.zhihuiyanche.service.users.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhihuiyanche.common.util.UUIDUtil;
import com.zhihuiyanche.dao.UsersMapper;
import com.zhihuiyanche.domain.Users;
import com.zhihuiyanche.domain.UsersExample;
import com.zhihuiyanche.service.users.UsersService;

@Component("usersService")
public class UsersServiceImpl implements UsersService {
	@Autowired
	private UsersMapper usersMapper;
	
	@Override
	public String insertUsers(Users users) {
		
        List<Users> usersList = getUsersByCondition(users);

        if(usersList.size() > 0){
            return "-1";
        }

        users.setId(UUIDUtil.generateGUID());
        users.setRoleLevel("0");
        users.setIsValid(0);
        String shopId = UUIDUtil.generateGUID();
        users.setShopId(shopId);
        users.setPassword(users.getPassword());
        usersMapper.insertSelective(users);
        return shopId;
    }

    @Override
	public List<Users> getUsersByCondition(Users users) {

        UsersExample example = new UsersExample();
        UsersExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(users.getUsername());
        if(users.getPassword() != null){
        	criteria.andPasswordEqualTo(users.getPassword());
        }
        final List<Users> userList = usersMapper.selectByExample(example);
		return userList;
	}
    
    @Override
	public boolean updatePassword(Users users) {
        
        return usersMapper.updatePassword(users)>0;
        
	}
	
	@Override
	public int getUsersByPageCount(Users users) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	@Override
	public boolean updateUsersByCondition(Users record, Users parameter) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteUsersById(Users users) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteUsersByCondition(Users users) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateUsersById(Users users) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Users getUsersById(Users users) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Users> getUsersAll(Users users) {
		// TODO Auto-generated method stub
		return null;
	}

}
